<?php

namespace app\api\controller;

use app\admin\model\ServersUser;
use app\api\model\AfterOrder;
use app\api\model\AfterOrderItem;
use app\api\model\AttachOrder;
use app\api\model\GradOrderRecord;
use app\api\model\Order;
use app\api\model\OrderItem;
use app\api\model\ServerUser;
use app\api\model\User;
use app\common\controller\ApiController;
use think\App;
use think\facade\Db;

class ServerOrder extends ApiController
{

    protected $noNeedLogin = [];
    protected $mustLogin = [];

    protected $wechat_config = [];
    // protected $allowModifyFileds = ['username', 'sort', 'status_text'];

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);
    }

    /**
     * 服务商生成二维码
     */
    public function create_bind_qrcode(Order $order,AfterOrder $afterOrder)
    {
        $param=$this->request->param();
        if (empty($param['order_id'])) {
            $this->error('未找到指定订单');
        }
        $type = empty($param['type'])?1:$param['type'];//1、普通单 2、售后单
        if ($type == 2) {
            $order = $afterOrder;
        } 
        $order_info =  $order->where('id', $param['order_id'])->where('service_uid', $this->uid)->find();
        if ($order_info['uid']) {
            $this->error('当前订单已有用户，不能绑定');
        }
        $wq = new WMinapp();
        $ret = $wq->get_qrcode('order', $param['order_id']);
        $order->where('id',$param['order_id'])->update(['bind_xcx_qrcode'=>$ret]);
        $this->success('获取成功', $ret);
    }


}
